/** 恐龙快打
  游戏按键设定为:连发a,连发b,设定为1帧按下4帧放开
  竖跳冲踢,需要根据人物改参数.
  后前拳连发的作用是截停跑步进行攻击,对我来说比较实用.
  摆拳已经放弃了...
  后投升龙成功率不高
  反而冲跑中的停跑连发拳比较实用

  By setycyas @2025-07-15
*/

/* 全局设定
*/ {
#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
;#Include "..\Class\FaceDetectorNC.2.ahk"
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\MyEmu.2.ahk"
#Include "..\Class\OrderMap.2.ahk"
;SendMode("Event")
SendMode("Input")
}

/* 制作恐龙快打的宏类
*/ class DinoMacro extends CommonMacro {

  pressDuration := 30

  /* 新增的宏函数
  */
  _单发拳(key){
    this._press(1)
  }
  
  ;打投时最后一拳用这个快捷键
  _后投升龙(key){
    ;延时,黄帽70,大块头要200,因为只用黄帽所以暂时不提供修改延时方式
    static delay1 := 80 
    MyFuns.keyDown("down")
    ;sleep(30)
    this._press(1)
    MyFuns.keyUp("down")
    sleep(delay1)
    MyFuns.press("down", 30)
    sleep(30)
    MyFuns.pressKeys(["up", this._keys[1]], [30, 50])
  }
  
  ;竖跳冲踢
  _竖跳冲踢(key){
    ;黄帽370,麦斯350
    static delay1 := 350
    this._press(2)
    sleep(delay1)
    ;sleep(this.testParams[1])
    this._press(1)
  }
  
  ;前冲急停
  _前冲急停(key){
    local face := this._face.face()
    local back := this._face.back()
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    MyFuns.press(face, 30)
    sleep(30)
    MyFuns.keyDown(face)
    loop {
      sleep(30)
    } until (!MyFuns.getVkState(vk))
    MyFuns.keyUp(face)
    sleep(30)
    MyFuns.press(back, 30)
    sleep(30)
    MyFuns.press(face, 30)
  }
  
  ;放开方向后前拳连发
  _后前拳连发(key){
    local face := this._face.face()
    local back := this._face.back()
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    MyFuns.clearDirections()
    ;MyFuns.keyUp(face)
    sleep(30)
    MyFuns.press(back, 30)
    sleep(30)
    MyFuns.press(face, 30)
    sleep(30)
    this._down(1)
    loop {
      sleep(30)
    } until (!MyFuns.getVkState(vk))
    this._up(1)
  }
  
  ;放开方向后前拳连发
  /*
  _停跑连发拳(key){
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    MyFuns.clearDirections()
    MyFuns.press("up", 30)
    sleep(30)
    this._down(1)
    loop {
      sleep(30)
    } until (!MyFuns.getVkState(vk))
    this._up(1)
  }
  */
  _停跑连发拳(key){
    local isPressingUp := MyFuns.getKeyState("up")
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    MyFuns.clearDirections()
    if isPressingUp {
      MyFuns.press("down", 30)
    } else {
      MyFuns.press("up", 30)
    }
    sleep(30)
    this._down(1)
    loop {
      sleep(30)
    } until (!MyFuns.getVkState(vk))
    this._up(1)
  }
  
  /*
  ;需要提升热键优先级,保证连发a途中也能ab
  _连发AB(key){
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    loop {
      this._press(3)
      sleep(30)
    } until (!MyFuns.getVkState(vk))
  }
  */
  ;后前,摆拳用,同时按住连发
  _后前(key){
    local face := this._face.face()
    local back := this._face.back()
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    local delay1 := this.testParams[1] ;150
    local delay2 := this.testParams[2] ;250
    MyFuns.press(back, delay1)
    sleep(30)
    MyFuns.press(face, delay2)
    sleep(30)
  }
  
  ;大汉:120,80,140
  ;太难实现,暂时放弃
  _摆拳(key){
    local face := this._face.face()
    local back := this._face.back()
    local thisKey := MyFuns.getHotkey(key)
    loop 2 {
      loop 2 {
        this._press(1)
        sleep(this.testParams[1])
        if (!GetKeyState(thisKey, "P")){
          return
        }
      }
      sleep(this.testParams[2])
      MyFuns.press(back, 60)
      this._press(1)
      sleep(this.testParams[3])
      if (!GetKeyState(thisKey, "P")){
        return
      }
      MyFuns.press(face, 40)
      sleep(40)
    }
    this._连发A(key)
  }

  /* 重载宏接口
  */
  _setMacro(){
    static obm := ObjBindMethod ;函数名简写,制作对象绑定函数
    ;制作宏相关Map
    this.macroMap := OrderMap()
    this.macroMap["连发A"] := obm(this, "_连发A")
    this.macroMap["连发AB"] := obm(this, "_连发AB")
    this.macroMap["下上A"] := obm(this, "_下上A")
    ;this.macroMap["摆拳"] := this._摆拳.bind(this)
    this.macroMap["单发拳"] := obm(this, "_单发拳")
     this.macroMap["后跳"] := obm(this, "_后跳")
    this.macroMap["前冲A"] := obm(this, "_前冲A")
    this.macroMap["后投升龙"] := obm(this, "_后投升龙")
    this.macroMap["竖跳冲踢"] := obm(this, "_竖跳冲踢")
    this.macroMap["前冲急停"] := obm(this, "_前冲急停")
    this.macroMap["后前拳连发"] := obm(this, "_后前拳连发")
    this.macroMap["后前"] := obm(this, "_后前")
    this.macroMap["停跑连发拳"] := obm(this, "_停跑连发拳")
    ;制作指定宏顺序的数组
    this.macroArr := this.macroMap.getKeys()
  }
}

/* 制作恐龙快打专用UI 
*/
class DinoUI extends CommonUI {

  ;DEFAULT_HOTKEYS := "~d"
  ;EXE_ARRAY := [MyEmu.MAME, "arcade64.exe", MyEmu.XZONE]

  /* 构造函数
  */
  __New(macro){
    super.__New("恐龙快打", macro)
    this._preset := OrderMap([
      ;"黄帽", ["连发A", "竖跳冲踢", "后前", "前冲A", "连发AB"],
      "默认", ["停跑连发拳", "竖跳冲踢", "前冲A"], 
    ])
    ;this.MACRO_PRIORITY["连发A"] := "p-1"
    this._macro.UI := this ;绑定UI
  }

  /* 重写接口
  */

}

/* 运行当前脚本
*/ if (A_ScriptName == "恐龙快打.2.ahk") {
  ;face := FaceDetectorNC() ;方向检测对象
  ;方向检测对象
  face := FaceDetector() 
  ;宏对象,有界面时第二参数随便写
  macro := DinoMacro(face, []) 
  ;新建界面对象并显示
  ui := DinoUI(macro)
  ui.setup()
  ;更新组件内容
  ui._exeComboBox.Choose(MyEmu.MAME)
  ui._gameKeyEdit.Text := "s,d"
  ;ui._hotkeyEdit.Text := "~a,~w,~e,~f"
  ui._hotkeyEdit.Text := "~a,~w,~f"
  ui._fpsEdit.Text := 10
  ui._testEdit.Text := "150,250,60,30"
  ;ui.readPresetMenu("无连发")
  ui.readPresetMenu("默认")
  ;ui.readPresetMenu("无摆拳")
}
